﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace CanvasEx.DrawCore
{
    class DrawEllipse : DrawObject
    {
        Point left, right, up, down, center;
        double x, y, r;
        EllipseGeometry ellipse = new EllipseGeometry();


        public DrawEllipse(Painter p, Point center, double r)
            : base(p)
        {
            this.center = center;
            left = center - new Vector(r, 0);
            right = center + new Vector(r, 0);
            up = center + new Vector(0, r);
            down = center - new Vector(0, r);
            this.x = r;
            this.y = r;
            this.r = Math.Sqrt(Math.Pow(x, 2) - Math.Pow(y, 2));
            ellipse = new EllipseGeometry(center, r, r);
        }
        public DrawEllipse(Painter p, Point center, double x, double y)
            : base(p)
        {
            this.center  = center;
            left = center - new Vector(x, 0);
            right = center + new Vector(x, 0);
            up = center + new Vector(0, y);
            down = center - new Vector(0, y);
            ellipse = new EllipseGeometry(center, x, y);
            this.x = x;
            this.y = y;
            this.r = Math.Sqrt(Math.Pow(x, 2) - Math.Pow(y, 2));
        }

        public override Geometry GetGeometry()
        {
            return ellipse;
        }
        public override bool InGraph(Point Location, double SelectAccuracy)
        {
            if (Math.Abs(DrawHelper.Getdistance(Location, center - new Vector(r, 0))
                + DrawHelper.Getdistance(Location, center + new Vector(r, 0))
                - 2 * x) > SelectAccuracy * 5)
                return false;
            else
                return true;
        }

        public override List<Point> GetHotSpot()
        {
            return new List<Point>() { left, right, up, down, center };
        }
    }
}
